package com.isoft.demo.service.impl;

import com.isoft.demo.common.ResponseData;
import com.isoft.demo.dao.VehicleDao;
import com.isoft.demo.entity.CustomerInfo;
import com.isoft.demo.entity.Employee;
import com.isoft.demo.entity.Vehicle;
import com.isoft.demo.service.VehicleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Service
public class VehicleServiceImpl implements VehicleService {
    @Resource
    private VehicleDao vehicleDao;

    @Override
    public ResponseData addVehicle(Vehicle vehicle) {
        int n = vehicleDao.addVehicle(vehicle);
        ResponseData rs = new ResponseData();
        List list = new ArrayList();
        if(n > 0){
            rs.setCode(0);
            rs.setMsg("添加成功");
            list.add(vehicle);
            rs.setData(list);
        } else{
            rs.setCode(1);
            rs.setMsg("添加失败");
        }
        return rs;
    }


    @Override
    public ResponseData deleteVehicle(int vid) {
        int a = vehicleDao.deleteVehicle(vid);
        ResponseData rs = new ResponseData();
        if(a != 0){
            rs.setCode(0);
            rs.setMsg("删除成功！");
        } else{
            rs.setCode(1);
            rs.setMsg("删除失败!");
        }
        return rs;
    }


    @Override
    public ResponseData updateVehicle(Vehicle vehicle) {
        int m = vehicleDao.updateVehicle(vehicle);
        ResponseData rs = new ResponseData();
        if(m != 0){
            rs.setCode(0);
            rs.setMsg("修改成功！");
        } else{
            rs.setCode(1);
            rs.setMsg("修改失败!");
        }
        return rs;
    }

    @Override
    public ResponseData findAllVehicle() {
        List<Vehicle> list = vehicleDao.findAllVehicle();
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }

    @Override
    public ResponseData findByVid(Integer vid) {
        List<Vehicle>list = vehicleDao.findByVid(vid);
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        }else {
            rs.setCode(1);
            rs.setMsg("fail");
        }
        return rs;
    }

    @Override
    public ResponseData findIdle() {
        List<Vehicle> list = vehicleDao.findIdle();
        ResponseData rs = new ResponseData();
        if(list != null){
            rs.setCode(0);
            rs.setMsg("ok");
            rs.setData(list);
        } else {
            rs.setCode(1);
            rs.setMsg("error");
        }
        return rs;
    }
}
